package com.ruiysoft.crm.controller;

import org.apache.commons.lang3.builder.ToStringExclude;
import org.freeswitch.esl.client.IEslEventListener;
import org.freeswitch.esl.client.inbound.Client;
import org.freeswitch.esl.client.inbound.InboundConnectionFailure;
import org.freeswitch.esl.client.transport.event.EslEvent;
import org.freeswitch.esl.client.transport.message.EslMessage;
import org.junit.Test;

import java.util.List;
import java.util.UUID;

public class MyTest {
    @Test
    public void test() {
        Client client = new Client();
        try {
            String host = "120.27.24.202";
            int port = 7022;
            String password = "Suitang8900!";
            client.connect(host, port, password, 20);

        } catch (InboundConnectionFailure e) {
            e.printStackTrace();
        }

        // 注册事件处理程序
        client.addEventListener(new IEslEventListener() {
            @Override
            public void eventReceived(EslEvent eslEvent) {
                System.out.println("eventReceived: " + eslEvent.getEventName());
            }

            @Override
            public void backgroundJobResultReceived(EslEvent eslEvent) {
                System.out.println("backgroundJobResultReceived: " + eslEvent.getEventName());
            }
        });

        client.setEventSubscriptions("plain", "all");

        EslMessage response = client.sendSyncApiCommand("originate user/1009 &echo", "");
//        EslMessage response = client.sendSyncApiCommand("sofia status profile internal reg", "");
        List<String> list = response.getBodyLines();
        list.stream().forEach(item -> {
            System.out.println(item);
        });

//        while (true) {
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
    }
}
